package com.xm.spring5.service;

import com.xm.spring5.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

//默认值是类名称，首字母小写 ("userService")
//@Component
@Service
public class UserService {

    @Value(value = "abc")
    private String name;

    //定义dao类型属性
//    @Autowired
//    @Qualifier("userDaoImpl1")
//    private UserDao userDao;

    //    @Resource  //根据类型注入
    @Resource(name = "userDaoImpl1")  //根据名称注入
    private UserDao userDao;

    public void add() {
        System.out.println("service add.........." + name);
        userDao.add();
    }
}
